package net.oschina.arvin.sqlbuilder.utils;

import net.oschina.arvin.sqlbuilder.exceptions.SqlBuilderException;

import java.util.Collection;

/**
 * @author Arvin
 * @time 2017/11/15 23:42
 */
public class AssertUtil {

    public static void assertTrue(boolean bool, String message) {
        if (!bool) {
            throw new SqlBuilderException(message);
        }
    }

    public static void assertFalse(boolean bool, String message) {
        if (bool) {
            throw new SqlBuilderException(message);
        }
    }

    public static void assertNotNull(Object obj, String message) {
        if (null == obj) {
            throw new SqlBuilderException(message);
        }
    }

    public static void assertNotBlank(String value, String message) {
        if (Util.isBlank(value)) {
            throw new SqlBuilderException(message);
        }
    }

    public static void assertEquals(Object expect, Object actual, String message) {
        boolean bothNull = null == expect && null == actual;
        if (bothNull) {
            return;
        }
        if (null != expect && expect.equals(actual)) {
            return;
        }
        throw new SqlBuilderException(message);
    }

    public static void assertNotEmpty(Collection<?> collection, String message) {
        if (null == collection || collection.isEmpty()) {
            throw new SqlBuilderException(message);
        }
    }
}
